package com.csii.mobilebanking.user;

import com.csii.mobilebanking.R;
import com.csii.mobilebanking.tool.AppService;
import com.csii.mobilebanking.tool.HpConstants;
import com.csii.mobilebanking.tool.HpUtils;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class UserForget {
	public Context mContext;
    public RelativeLayout view;
	private TextView login_num;
	private Button login;
	private UserResettingBean userresetting;
	public UserForget(Context aContext) 
	{
		mContext = aContext;
		findView();
		loadData();
	}
	
	private void findView() 
	{
		view = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.hwzj_user_forget, null);	
		login_num = (TextView)view.findViewById(R.id.login_num);
		login=(Button)view.findViewById(R.id.login);
		login.setOnClickListener(forgetClick);
	}
	
	private void loadData(){
		userresetting=new UserResettingBean();
	}
	
	public OnClickListener forgetClick = new OnClickListener() {
		@Override
		public void onClick(View v) {
			String error = getError();
			if (!error.equals("")){
				HpToast.showMessageBottom(mContext, error);
			}
			else{
				String loginNumber = login_num.getText().toString();
				new ForgetTask().execute(new String[] {loginNumber});
			}
		}
	};
	
	private String getError(){
		String loginNumber = login_num.getText().toString();
		String returnval="";
		if(loginNumber == null || loginNumber.equals(""))
		{
			login_num.requestFocus();
			return "请输入手机号码";
		}
		if(loginNumber.length() < 11)
		{
			login_num.requestFocus();
			return "请输入11个手机号码,您的输入少于11个";
		}
		if(loginNumber.length() > 11)
		{
			login_num.requestFocus();
			return "请输入11个手机号码,您的输入大于11个";
		}

		return returnval;
	}
	
	class ForgetTask extends AsyncTask<String, Integer, Object>
	{
	
		@Override  
		protected void onPreExecute() 
		{  
			super.onPreExecute();  
			HpDialog.show(mContext, HpConstants.MsgLoginProcess);
		} 
		@Override    	
		protected void onPostExecute(Object result) { 
			HpDialog.close();
			TResponse resp = (TResponse)result;
			if (HpUtils.isOk(resp)){
//				HpUtils.AcUserResetting(mContext,userresetting);

			}
			else{
				String memo = HpUtils.getMemo(resp);
				if (memo.equals("")){
					HpToast.showMessageBottom(mContext, HpConstants.MsgLoginError + "," + HpConstants.MsgCheckNet);
				}
				else{
					HpToast.showMessageBottom(mContext, HpConstants.MsgLoginError + memo);
				}
			}
			super.onPostExecute(result);          
		}  

		@Override
		protected Object doInBackground(String... params) {
			String loginNumber = login_num.getText().toString();
//			return AppService.forget(loginNumber,userresetting);
			return loginNumber;
		}		
	}
	
}
